//
//  RDKUtility.h
//  FoxitApp
//
//  Created by Christine on 11/24/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MessageUI/MessageUI.h>

#import <ifaddrs.h>
#import <netinet/in.h>
#import <sys/socket.h>
#import "ColorUtility.h"
#import "FXEnum.h"
#import "DmUtil.h"

//@class DmDocMgr;

#define FOXIT_LOG_ON YES
#define FOXIT_IDENTIFIER @"com.aerospacefoxit.reader"
//Foxit log, use this instead of NSLog


#define fequal(a,b) (fabs((a) - (b)) < FLT_EPSILON)

static const NSString *ATTACHMENT_DATA = @"Attachment_Data";
static const NSString *ATTACHMENT_MIMETYPE = @"Attachment_Mimetype";
static const NSString *ATTACHMENT_FILENAME = @"Attachment_FileName";

typedef void(^sendEmailClosed)(MFMailComposeResult result);



@interface NSString (UUID)
+ (NSString *)stringWithNewUUID;
@end

@interface RDKUtility : NSObject <MFMailComposeViewControllerDelegate>
{}

@property (copy, nonatomic) sendEmailClosed sendEmailClosedHandler;


//display date in yyyy-MM-dd formate
+ (NSString *)displayDateInYMD:(NSDate *)date;

//display date in yyyy-MM-dd HH:mm formate
+ (NSString *)displayDateInYMDHM:(NSDate *)date;

//display date in "yyyy-MM-dd HH:mm" or "yyyyMMddHHmm"
+ (NSString *)displayDateInYMDHM:(NSDate *)date hasSymbol:(BOOL)hasSymbol;

//display date in "yyyyMMddHHmmss" or "D:yyyyMMddHHmmss+08'00'"
+ (NSString*)displayDateInYMDHMS:(NSDate*)date hasZone:(BOOL)hasZone;

//string formater "yyyyMMddHHmm" to date
+ (NSDate *)dateFromString:(NSString*)dateString;

//stringformater "yyyyMMddHHmmss" to date
+ (NSDate *)dateFromStringYMDHMS:(NSString*)dateString;

//display the file size string
+ (NSString *)displayFileSize:(unsigned long long)Byte;

//remove all gesture
+ (void)removeAllGestureRecognizer:(UIView*)view;

// get current device memory mode
+ (int)getMemoryMode;

// absolute path and relative path
// the path used in DB is relative path, others uses absolute path
// this is because when reinstall iOS or restore App, the bundle path for App will change. Cannot use absolute path in DB otherwise it will not work
+ (NSString *)absolutePathToRelativePath:(NSString *)absolutePath;
+ (NSString *)relativePathToAbsolutePath:(NSString *)relativePath;

// get folder size
+ (unsigned long long int)folderSize:(NSString *)folderPath;

// get file size
+ (unsigned long long)fileSize:(NSString *)filePath;

//adjust the image frame according to image
+ (void)assignImage:(UIImageView *)imageView rawFrame:(CGRect)frame image:(UIImage *)image;

/** @brief Verify if point is in polygon. */
+ (BOOL)isPointInPolygon:(CGPoint)p polygonPoints:(NSArray*)polygonPoints;

/** @Get Rect by two points. */
+ (CGRect)convertToCGRect:(CGPoint)p1 p2:(CGPoint)p2;

/** @brief Get Rect by two points. */
+ (FSRectF *)convertToFSRect:(FSPointF *)p1 p2:(FSPointF *)p2;

/** @brief Standard Rect. */
+ (CGRect)getStandardRect:(CGRect)rect;

//Get test size by font
+ (CGSize)getTestSize:(UIFont*)font;

//Add animation
+ (void)addAnimation:(CALayer*)layer type:(NSString*)type subType:(NSString*)subType timeFunction:(NSString*)timeFunction duration:(float)duration;

/** @brief Get UUID. */
+ (NSString *)getUUID;

//获得当前的时间戳唯一id字符串(整型)
+ (NSString *)getUniqueId_integerStr;

//获取parentFolder中所有空目录
+ (NSArray *)searchEmptyFoldersWithParentFolder:(NSString *)parentFolder;

//测试目录是否为空
+ (BOOL)isEmptyFolder:(NSString *)folder;

//获取文件夹中的文件
+ (NSArray *)searchFilesWithFolder:(NSString *)folder recursive:(BOOL)recursive;

//获取文件夹之下的文件夹
+ (NSArray *)searchFoldersWithFolder:(NSString *)folder recursive:(BOOL)recursive;

//裁剪图片
+ (UIImage *)cutImage:(UIImage *)fromImage cutFrame:(CGRect)frame;

//判断是否是Retina屏幕
+ (BOOL)isRetina;

//send email
+ (void)sendEmail:(NSString *)title body:(NSString *)htmlBody to:(NSArray *)toPerson cc:(NSArray *)ccPerson bcc:(NSArray *)bccPerson attachment:(NSArray *)attachments onView:(UIViewController *)presentViewController closeHandler:(sendEmailClosed)sendEmailClosedHandler;

//check whether after the requiredVersion
+ (BOOL)isSinceiOS:(const NSString *)requiredVersion;

// 获取app产品名称
+ (NSString *)productName;
// 获取app版本号
+ (NSString *)productVersion;

//------以下方法主要用于iPhone版本在旋转后NavigationBar的按钮自动调整尺寸
+ (void)layoutButtonOfNavigationBar:(UINavigationBar *)bar view:(UIView *)view;

//reverse to get UIViewController from a view
+ (UIViewController *)getViewController:(UIView *)view;

//获取当前设备的尺寸模式
+ (ScreenSizeMode)getScreenSizeMode;

//创建目录,存在直接返回
+ (void)createFolderWithFolder:(NSString *)folder;

//创建并返回目录
+ (NSString *)createFolderWithFolder:(NSString *)folder prefixFolder:(NSString *)prefixFolder caseSensitive:(BOOL)caseSensitive;

//从一个目录返回所有子目录和文件 返回对象为 MutableDictionary(MutableDictionaryPathInfo) 对象数组
+ (NSArray *)getFoldersAndFiles:(NSString *)folder;

//将字符串文件或者目录列表 转换为MutableDictionary(MutableDictionaryPathInfo) 对象数组
+ (NSArray *)convertStringFilesToDictFiles:(NSArray *)files;

//Get mac address, the output is for example: 00:23:32:CB:AB:80
+ (NSString *)getMacAddress;

//Layout a UIButton, make it image top and text bottom
+ (void)layoutButtonWithImageAboveText:(UIButton*)button spacing:(float)spacing;

//Get mime type from extension
+ (NSString*)getMimeTypeFromExtension:(NSString*)filePath;

////Take screen shot
+ (UIImage*)screenShot:(UIView*)view;

//Crop image
+ (UIImage*)cropImage:(UIImage*)img rect:(CGRect)rect;

//Convert NSDate to hex
+ (NSString*)convertNSDateToHex:(NSDate*)date;

////Dectect dead loop
+ (BOOL)isDeadLoopDetected;
//
////Fix image orientation
//+ (UIImage *)normalizedImage:(UIImage*)img;
//

/// Verify file type - 判断是不是pdf 或 ofd
+ (BOOL)isPDFPOrOfdPath:(NSString *)path;

////Verify file type
+ (BOOL)isPDFPath:(NSString*)path;
+ (BOOL)isPPDFPath:(NSString*)path;

/// Verify file type - 是否是pdf 文档
+ (BOOL)isPDFPathFile:(NSString *)path;

/// 验证文件路径是不是ofd 后缀格式的
/// @param path 文件路径
+ (BOOL)isOFDPath:(NSString *)path;

+ (BOOL)isPDFExtension:(NSString *)extension;
+ (BOOL)isGivenPath:(NSString *)path type:(NSString *)type;
+ (BOOL)isGivenExtension:(NSString *)extension type:(NSString *)type;

//File/Folder existance
+ (BOOL)isFileOrFolderExistAtPath:(NSString *)path fileOrFolderName:(NSString *)fileOrFolderName;

//Get file type icon name -pdf 或 ofd
+ (NSString *)getPdfAndOfdIconName:(NSString *)path;

//Get file type icon name
+ (NSString *)getIconName:(NSString *)path;

+ (NSString *)filterEmoji:(NSString *)string;

//Get file type thumbnail name - pdf/ofd 和 其他
+ (NSString *)getPdfOrOfdThumbnailName:(NSString *)path;

//Get file type thumbnail name - -区分各种类型
+ (NSString *)getThumbnailName:(NSString *)path;

//Remove not needed file type
+ (NSArray*)removeSomeFileType:(NSArray*)array isRoot:(BOOL)isRoot;

//check a zip file is encrypted.
+ (BOOL)isZipEncrypted:(NSString *)path;

+ (NSArray*)currentDeviceIpList;

+ (void)actionSelecterOfModules:(NSArray*)modules protocol:(Protocol*)prol selecter:(SEL)sel;

+ (BOOL)isWifiAvailable;
+ (BOOL)isOnline;

+ (CountryType)getCountryType;

+(void)dismissAnnotationType;
+ (UIButton*)createItemWithImageAndTitle:(NSString*)title
                             imageNormal:(UIImage*)imageNormal
                           imageSelected:(UIImage*)imageSelected
                            imageDisable:(UIImage*)imageDisabled;

+ (CGSize)getTextSize:(NSString*)text fontSize:(float)fontSize maxSize:(CGSize)maxSize;

/** @brief Get the texts size from attributed string. */
+ (CGSize)getAttributedTextSize:(NSAttributedString *)attributedString maxSize:(CGSize)maxSize;
+ (NSAttributedString *) getAttributedStringWithText:(NSString *)aString andCount:(int)selectedFileCount;

/** @brief Get the adjusted size according to current scale. */
+ (CGFloat)realPX:(CGFloat)wantPX;
+(UIImage*)scaleToSize:(UIImage*)oriImage size:(CGSize)size;
/// 返回打开文档状态码说明
/// @param state 打开文档的状态码
+ (NSString *)openFileStateString:(enum FS_ERRORCODE)state;
/// 获取检查授权文件状态说明
/// @param state 状态码
+ (NSString *)checkLicenseStateString:(enum FS_GSDK_LICENSE_ERRORCODE)state;
/** @brief Apply alpha with the origin image. */
+ (UIImage *)imageByApplyingAlpha:(UIImage *)image alpha:(CGFloat)alpha;
#pragma mark - copy file
+ (BOOL)copyPDFFromResourceToDocumentsFoldName:(NSString*)foldName
                                      FileName:(NSString*)filename
                                          Type:(NSString*)type
                                     overwrite:(BOOL)overwrite;

+ (BOOL)copyPDFFromResourceToDocumentsFoldName:(NSString*)foldName
                                      FileName:(NSString*)filename
                                          Type:(NSString*)type
                                     overwrite:(BOOL)overwrite
                                      fromPath:(NSString *)fromPath;

+ (BOOL)copyPDFFromResourceToDocuments:(NSString*)filename
                                  Type:(NSString*)type
                             overwrite:(BOOL)overwrite
                                toPath:(NSString *)finalPath;

+ (BOOL)copyPDFFromResourceToDocuments:(NSString*)filename
                                  Type:(NSString*)type
                             overwrite:(BOOL)overwrite;

+ (NSString *)copyPDFFromResourceToDocumentsKmyPng:(NSString*)filename
                                              Type:(NSString*)type
                                         overwrite:(BOOL)overwrite;

/// 获取app信息 唯一标识 + 应用包名
+ (NSString *)getAppInfo;

/// 获取appid信息
+ (NSString *)getAppIdentifier;

/// 获取存储在钥匙串中的UUID
+ (NSString *)getAppKeychainUUID;

/// 获取top bar 的高度
+ (CGFloat)heightOfTopbarOrientation:(UIInterfaceOrientation)orientation;

/// 校验文件路径是否可打开/下载
/// @param filePath filePath
/// @param completion 若返回本地路径 则证明可以打开/下载
/// @param errorHandler 返回error 证明不可打开/下载 以及相关的错误信息
+ (void)checkURLIsPDFOrOFDFile:(NSString *)filePath
                    completion:(void (^)(NSString *localFilePath))completion
                  errorHandler:(void (^)(NSString *errorMessage,FX_URL_RESULT_STATE state))errorHandler;

/// 复制文件 - 从工程文件到沙盒文件
/// @param filename filename
/// @param type 类型
/// @param overwrite 是否覆盖
/// @param finalPath  目标路径，若为空 则使用默认路径MRSDK_DOCUMENT_PATH / MRSDK_FILE_PATH
+ (BOOL)copyFileFromResourceToDocuments:(NSString *)filename
                                   type:(NSString *)type
                              overwrite:(BOOL)overwrite
                                 toPath:(NSString *)finalPath;

/// 加载字体 - -需要在demo中添加字体库
/// CESI_FS_GB2312.TTF / CESI_HT_GB2312.TTF / CESI_KT_GB2312.TTF / CESI_SS_GB2312.TTF / CESI_XBS_GB2312.TTF / NotoSansSC-Regular.otf /
+ (void)loadDefaultFont;
@end
